import AsyncStorage from '@react-native-async-storage/async-storage';

// 存储令牌
export const storeToken = async (token: string) => {
  try {
    await AsyncStorage.setItem('@auth_token', token);
    return true;
  } catch (error) {
    console.error('存储令牌失败:', error);
    return false;
  }
};

// 获取令牌
export const getToken = async (): Promise<string | null> => {
  try {
    const token = await AsyncStorage.getItem('@auth_token');
    return token;
  } catch (error) {
    console.error('获取令牌失败:', error);
    return null;
  }
};

// 清除令牌（登出）
export const clearToken = async () => {
  try {
    await AsyncStorage.removeItem('@auth_token');
    return true;
  } catch (error) {
    console.error('清除令牌失败:', error);
    return false;
  }
};

// 检查是否已登录
export const isLoggedIn = async (): Promise<boolean> => {
  const token = await getToken();
  return !!token;
}; 